//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name: wbtcnctn.h

Abstract:

Notes:
--*/


#ifndef __WBTCNCTN_H__
#define __WBTCNCTN_H__

#include "wbtclnts.h"

/*++

--*/

extern const LPWSTR szRegKeyTaskmanSettings;
extern const LPWSTR szRegKeyConnections;
extern const LPWSTR szRegValLastPID;
extern const LPWSTR szRegKeyTaskmanRunAtStartup;

typedef struct
tagConnectData {
   LPWSTR   lpszConnectionKey;
   LPWSTR   lpszClientRegistrationKey;
   LPWSTR   lpszType;
   LPWSTR   lpszDescription;
   LPWSTR   lpszStartExe;
   LPWSTR   lpszStartCmdLineArgs;
   LPWSTR   lpszPropertiesExe;
   LPWSTR   lpszPropertiesCmdLineArgs;
   LPWSTR   lpszDeleteExe;
   LPWSTR   lpszDeleteCmdLineArgs;
   HWND     hwnd;
   PROCESS_INFORMATION pi;
   CLIENT_CLASS clientClass;
} CONNECT_DATA, *PCONNECT_DATA;



/*++

--*/

typedef class
CConnectList : public CClientList{

   typedef class CConnectEntry {

   public:      
      PCONNECT_DATA cdata;
      INT index; 
      DWORD dwStartupFlag;   
   private:      
      CConnectEntry *next;
      CConnectEntry *prev;
      friend class CConnectList;
      
   } CONNECT_ENTRY, *PCONNECT_ENTRY;


public:
          
          CConnectList();
         ~CConnectList();
   VOID  DeleteConnectionFromList(INT index);      
   VOID  EnumConnections();
   BOOL  FindConnectionHwnd(INT index);
   BOOL  FindConnectionNew(INT client);
   INT   GetActiveSessionCount();
   INT   GetActiveSessionNext(INT iReference);
   INT   GetActiveSessionPrev(INT iReference);
   INT   GetDefault();   
   INT   GetConnectionCount();
   BOOL  GetConnectionDataByIndex(INT index, PCONNECT_DATA &cdata);    
   DWORD GetConnectionStartupInfo(INT index);  
   VOID  GetStartupInfo();
   BOOL  InitInstance(BOOL bRestart);      
   BOOL  IsDefaultAutostart(INT index);   
   VOID  RescanConnectionFromRegistry(INT item);             
   VOID  SetDefault(INT index);
   BOOL  WriteDefault(INT index, BOOL autostart);

#ifdef DEBUG
   VOID  DbgDumpConnections();
#endif

private:
   
   PCONNECT_ENTRY head;
   PCONNECT_ENTRY tail;
   BOOL bRestart;

   VOID  ClearDefault();
   VOID  ClearStartupFlags();
   VOID  DeleteAllConnections();
   VOID  DeleteConnectionFromList(PCONNECT_ENTRY ptr);   
   VOID  FreeConnectionData(PCONNECT_DATA cdata);
   INT   GetConnectionIndexByConnKey(LPWSTR lpszConnKey);
   INT   GetConnectionIndexByConnKeyAndClientKey(LPWSTR lpszConnKey, LPWSTR lpszClientKey);
   INT   GetDefaultIndex();
   VOID  InsertConnection(PCONNECT_DATA cdata);
   VOID  LoadConnections();
   BOOL  QueryDefaultSettings(LPWSTR szClientKey, LPWSTR szConnectKey);
   BOOL  QueryAutostartSetting();
   BOOL  ReadConnectionFromRegistry(HKEY hkey, PCONNECT_DATA cdata);   
   BOOL  ReadConnectionValues(HKEY hkey, PCONNECT_DATA cdata);
   VOID  SetAutostart(BOOL autostart);
   VOID  ValidateConnectionPID(PCONNECT_DATA cdata, DWORD dwProcessId);
   BOOL  WriteDefaultToReg(INT index, BOOL autostart);
   
   static BOOL CALLBACK FindWindowProc(HWND hwnd, LPARAM lParam);

} CONNECT_LIST, *PCONNECT_LIST;



#endif // __WBTCNCTN_H__



